<template>
	<view class="relative">
		<u-icon name="close" class='white absolute login_back' @click="backindex"></u-icon>
		<view class="absolute login_bg" style="">
			<image class="photo" src="../../static/home/yaoqingdaohang.png" mode="aspectFit"></image>
		</view>
		<view class="" style="height: 270rpx;">

		</view>
		<view class="login p10" style="">
			<view class="radius-46 mt-60">
				<view class="size-26 ml-40">
					手机号
				</view>
				<u-field v-model="phone" :border-bottom="true" label-width="0" placeholder="请输入手机号登录"
					placeholder-style="color:#999;font-size:26rpx;">

				</u-field>
				<!-- <view class="tipsbox" v-if="isshow">手机号必填</view> -->
			</view>
			<view class="size-26 ml-40 mt-30">
				验证码
			</view>
			<view class="mt-40 radius-46 ">
				<u-field v-model="code" placeholder="请填写验证码">
					<u-button size="mini" slot="right" type="success" @click="getCode">{{codeText}}</u-button>
				</u-field>
				<u-verification-code ref="uCode" @change="codeChange"></u-verification-code>
			</view>
			<view class="ouaccount relative">

				<view class="mt-40" @click="submitUser()" style="">
					<u-button hover-class="none" class="custom-style" style="color: #FFF;" :style="{background:bg}"
						:hair-line="false" :disabled='bool'>登录
					</u-button>
				</view>
				<view class="mt-40 size-26 flex1 " style="align-items: center;">
					<u-checkbox-group @change="checkboxGroupChange">
						<u-checkbox shape="circle" @change="checkboxChange" v-model="item.checked"
							v-for="(item, index) in list" :key="index" :name="item.name">{{item.name}}</u-checkbox>
					</u-checkbox-group>
					<view class="login_che">
						《用户服务协议》
					</view>
					<view class="login_che">
						《隐私政策》
					</view>
				</view>
			</view>
			<!-- 	<view class="Login_agreement"> 
					<u-checkbox-group class="" active-color="#44acff">
						<u-checkbox v-model="checked" shape="circle">
							<view class="policytext">
							        已阅读并同意<text  @click="toAgreement">《用户协议》</text>和<text @click="toPolicy">《隐私政策》</text>
							</view>
						</u-checkbox>
					</u-checkbox-group>
				</view> -->

		</view>
	</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				checked: false,
				phone: '18315057303',
				mobile: '',
				code: '',
				codeText: '',
				bool: false,
				bg: ' linear-gradient(to right, #CDCDCD, #BEBEBE)',
				list: [{
					name: '已阅读并同意',
					checked: false,
					disabled: false
				}, ],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				value: 'orange',
			}
		},
		methods: {
			// 选中任一checkbox时，由checkbox-group触发
			checkboxGroupChange(e) {
				// console.log(e);
			},
			// 选中某个复选框时，由checkbox时触发
			checkboxChange(e) {
				// console.log(e.value);
				if (e.value) {
					this.bg = "linear-gradient(to right, #606060, #2B2B2B)"
					this.bool = true
					console.log(this.bool, this.bg, "开");

				} else {
					this.bg = "linear-gradient(to right, #CDCDCD, #BEBEBE)"
					this.bool = false
					console.log(this.bool, this.bg, "关");

				}
			},
			backindex() {
				uni.switchTab({
					url: '/pages/home/index'
				})
			},
			codeChange(text) {
				this.codeText = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
						console.log(111);
						this.$http('api/login/sendCode', {
							phone: this.phone,
							type: 2
						}, 'POST').then(res => {
						 console.log(res);
						})
					}, 1000);
				} else {
					this.$u.toast('倒计时结束后再发送');
					console.log(1);
				}
			},
			submitUser() {
				if(this.code==''){
					uni.showToast({
						title:'请输入认证码',
						icon:'none'
					})
				}else{
					this.$http('api/login/login', {
						phone: this.phone,
						password: this.password
					}, 'POST').then(res => {
						uni.showToast({
							title: '登录成功'
						})
						uni.setStorageSync("token", res.app_token)
						uni.setStorageSync("im_token", res.im_token)
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/home/index'
							})
						}, 500)
					})
				}
	 
			}
		}
	}
</script>
<style lang="less" scoped>
	page {
		background-color: #333333;
	}

	.login_che {
		color: #0813de;
	}

	.login_bg {
		width: 500rpx;
		height: 100rpx;
		top: 10%;
		left: 50%;
		transform: translateX(-50%);
	}

	.login_back {
		width: 500rpx;
		height: 100rpx;
		top: 0%;
		left: 38%;
		transform: translateX(-50%);
	}

	.login {
		background-color: #fff;
		width: 100%;
		height: 1065rpx;
		border-radius: 30rpx 30rpx 0 0;
	}

	::v-deep  .u-field-inner {
		display: block;
	}

	.bottombox {

		// position: fixed;
		// bottom: 10rpx;
		.Login_agreement {
			color: #c8c8c8;
			font-size: 20rpx;
			display: flex;
			// margin-bottom: 20rpx;
		}
	}

	.policytext {
		font-size: 20rpx;
	}

	.ouaccount {
		width: 90%;
		height: 100rpx;
		border-radius: 20rpx;
		// position: fixed;
		bottom: 0%;
		left: 50%;
		// text-align: center;
		transform: translateX(-50%);


	}
</style>
